/*
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 *
 * Copyright @2008 the original author or authors.
 */
package com.bluestone.core;

import com.bluestone.util.Util;

/**
 * @author <a href="mailto:bluestone.daniel.q@gmail.com">daniel.q</a>
 * 
 */
public class ActionFactory {
	public static String MOVEACTION = "move";

	public static String DELAYACTION = "delay";

	public static String CLICKACTION = "click";

	public static String INPUTTEXTACTION = "inputtext";

	public static String INPUTKEYACTION = "inputkey";

	public static String MAXPAGEACTION = "maxpage";

	public static String CLOSEPAGEACTION = "closepage";

	public static String RUNACTION = "run";

	public static String SELECTLISTACTION = "selectlist";

	public static String CHECKTRUEACTION = "checktrue";

	public static String CHECKFALSEACTION = "checkfalse";

	public static String WINRUNACTION = "winrun";

	public static String FOCUSACTION = "focus";
	public static String SAVEASACTION="saveAs";
	public static String COMPAREIMAGEACTION="compareImage";
	public static String BACKPAGEACTION="backpage";
	public static String CHECKRGBACTION="checkrgb";
	public static String CHECKBROWSERACTION ="checkbrowser";
	
	public static String MINPAGEACTION = "minpage";
	
	public static String RESETKEYSACTION = "resetkeys";
	
	public static String CLOSEALLPAGESACTION = "closeallpages";
	
	public static String CALLFUNCTIONACTION = "callfunction";
	
	public static String OPENURLACTION = "openurl";
	
	public static String SETCURRENTPAGEACTION = "setcurrentpage";
	
	public static String OPENPAGEACTION = "openpage";
	
	public static String CLOSECURRENTPAGEACTION = "closecurrentpage";
	
	public static String REMOVECURRENTPAGEACTION = "removecurrentpage";
	
	public static String NEXTFOCUSACTION = "nextfocus";
	
	public static String SCREENSHOTACTION = "screenshot";
	
	public static String SAVEASIMAGEACTION = "saveasimage";
	
	public static String SAVEASFILEACTION = "saveasfile";
	
	public static String ROBOTACTION = "robot";
	
	public static String INTERCEPTACTION = "intercept";
	
	public static String CHECKPROJECTACTION = "checkproject";
	
	public static String CLOSEALLWINDOWSACTION = "closeallwindows";
	


	/**
	 * Acording the type to generate action.
	 * @param type String that defines the type of the action.
	 * @param target String that defines the graphical elements operated by action.
	 * @param value String that defines the value of the action.
	 * @param delay String that defines the delay time after the action finished.
	 * @param offset String that defines the offset of the graphical elements.
	 * @return Action 
	 */
	public static Action createAction(String type, String target, String value,
			String delay, String offset) {
		Action result = null;
		if (MOVEACTION.equalsIgnoreCase(type)) {
			result = new MoveAction(type, target, value, delay, offset);
		} else if (DELAYACTION.equalsIgnoreCase(type)) {
			result = new DelayAction(type, target, value, delay, offset);
		} else if (CLICKACTION.equalsIgnoreCase(type)) {
			result = new ClickAction(type, target, value, delay, offset);
		} else if (INPUTTEXTACTION.equalsIgnoreCase(type)) {
			result = new InputTextAction(type, target, value, delay, offset);
		} else if (INPUTKEYACTION.equalsIgnoreCase(type)) {
			result = new InputKeyAction(type, target, value, delay, offset);
		} else if (CHECKTRUEACTION.equalsIgnoreCase(type)) {
			result = new CheckTrueAction(type, target, value, delay, offset);
		} else if (CHECKFALSEACTION.equalsIgnoreCase(type)) {
			result = new CheckFalseAction(type, target, value, delay, offset);
		} else if (MAXPAGEACTION.equalsIgnoreCase(type)) {
			result = new MaxPageAction(type, target, value, delay, offset);
		} else if (CLOSEPAGEACTION.equalsIgnoreCase(type)) {
			result = new ClosePageAction(type, target, value, delay, offset);
		} else if (RUNACTION.equalsIgnoreCase(type)) {
			result = new RunAction(type, target, value, delay, offset);
		} else if (SELECTLISTACTION.equalsIgnoreCase(type)) {
			result = new SelectListAction(type, target, value, delay, offset);
		} else if (WINRUNACTION.equalsIgnoreCase(type)) {
			result = new WinrunAction(type, target, value, delay, offset);
		} else if (FOCUSACTION.equalsIgnoreCase(type)) {
			result = new FocusAction(type, target, value, delay, offset);
		}else if(SAVEASACTION.equalsIgnoreCase(type)){
			result = new SaveAsAction(type,target,value,delay,offset);
		}else if(COMPAREIMAGEACTION.equalsIgnoreCase(type)){
			result= new CompareImageAction(type,target,value,delay,offset);
		}else if(BACKPAGEACTION.equalsIgnoreCase(type)){
			result= new BackPageAction(type,target,value,delay,offset);
		}else if(CHECKRGBACTION.equalsIgnoreCase(type)){
			result= new CheckRGBAction(type,target,value,delay,offset);
		}else if(CHECKBROWSERACTION.equalsIgnoreCase(type)){
			result = new CheckBrowserAction(type,target,value,delay,offset);
		}else if(MINPAGEACTION.equalsIgnoreCase(type)){
			result = new MinPageAction(type,target,value,delay,offset);
		}else if(RESETKEYSACTION.equalsIgnoreCase(type)){
			result = new ResetKeysAction(type,target,value,delay,offset);
		}else if(CLOSEALLPAGESACTION.equalsIgnoreCase(type)){
			result = new CloseAllPagesAction(type,target,value,delay,offset);
		}else if(CALLFUNCTIONACTION.equalsIgnoreCase(type)){
			result = new CallFunctionAction(type,target,value,delay,offset);
		}else if(OPENURLACTION.equalsIgnoreCase(type)){
			result = new OpenURLAction(type,target,value,delay,offset);
		}else if(SETCURRENTPAGEACTION.equalsIgnoreCase(type)){
			result = new SetCurrentPageAction(type,target,value,delay,offset);
		}else if(OPENPAGEACTION.equalsIgnoreCase(type)){
			result = new OpenPageAction(type,target,value,delay,offset);
		}else if(CLOSECURRENTPAGEACTION.equalsIgnoreCase(type)){
			result = new CloseCurrentPageAction(type,target,value,delay,offset);
		}else if(REMOVECURRENTPAGEACTION.equalsIgnoreCase(type)){
			result = new RemoveCurrentPageAction(type,target,value,delay,offset);
		}else if(NEXTFOCUSACTION.equalsIgnoreCase(type)){
			result = new NextFocusAction(type,target,value,delay,offset);
		}else if(SCREENSHOTACTION.equalsIgnoreCase(type)){
			result = new ScreenshotAction(type,target,value,delay,offset);
		}else if(SAVEASIMAGEACTION.equalsIgnoreCase(type)){
			result = new SaveAsImageAction(type,target,value,delay,offset);
		}else if(SAVEASFILEACTION.equalsIgnoreCase(type)){
			result = new SaveAsFileAction(type,target,value,delay,offset);
		}else if(ROBOTACTION.equalsIgnoreCase(type)){
			result = new RobotAction(type,target,value,delay,offset);
		}else if(INTERCEPTACTION.equalsIgnoreCase(type)){
			result = new InterceptAction(type,target,value,delay,offset);
		}else if(CHECKPROJECTACTION.equalsIgnoreCase(type)){
			result = new CheckProjectAction(type,target,value,delay,offset);
		}else if(CLOSEALLWINDOWSACTION.equalsIgnoreCase(type)){
			result = new CloseAllWindowsAction(type,target,value,delay,offset);
		}
		if(result == null){
			Util.error("invalid action type:"+type);
			System.exit(-1);
		}
		return result;
	}

}
